local M = {}

function M.config()
  require('gitsigns').setup {
    signs = {
      add = { text = '┃' },
      change = { text = '┃' },
      delete = { text = '┃' },
      topdelete = { text = '┃' },
      changedelete = { text = '┃' },
    },
    on_attach = function(bufnr)
      local gs = require('gitsigns')
      local function map(mode, l, r, opts)
        opts = opts or {}
        opts.buffer = bufnr
        vim.keymap.set(mode, l, r, opts)
      end

      -- 这里是与 coc-git 相同的快捷键配置
      -- 更新 gitsigns 的快捷键配置
      map('n', 'gs', gs.preview_hunk)
      map('n', '<leader>gu', gs.undo_stage_hunk)
      map('n', '<leader>gr', gs.reset_hunk)
      map('n', '<leader>gp', gs.stage_hunk)
      map('n', '<leader>gb', gs.blame_line)
      map('n', '<leader>gS', gs.stage_buffer)
      map('n', '<leader>gR', gs.reset_buffer)
      map('n', '<leader>gP', gs.toggle_current_line_blame)
      map('n', '<leader>gd', gs.diffthis)
      map('n', '<leader>gD', function() gs.diffthis('~') end)
      map('n', '<leader>gj', gs.next_hunk)
      map('n', '<leader>gk', gs.prev_hunk)
    end,
  }
end

return M
